package main

import (
	"log"
	"net"
	"net/http"
	"net/rpc"
)

//rpc 结构体
type RPCStruct struct {
}

//请求结构体
type RPCReq struct {
	A, B int64
}

//响应结构体
type RPCResp struct {
	SumNum int64
}

func (rpc *RPCStruct) SumDo(req RPCReq, resp *RPCResp) error {
	resp.SumNum = req.A + req.B
	log.Printf("求和sum=%d", resp.SumNum)
	return nil
}
func main() {
	rp := new(RPCStruct)
	//注册rpc
	rpc.Register(rp)
	rpc.HandleHTTP()
	//tcp 服务端的listener
	listener, e := net.Listen("tcp", ":1234")
	//日志输出监听
	log.Println("start listen ing~~~~")
	if e != nil {
		panic(e)
	}
	//使用的 http 监听
	http.Serve(listener, nil)
}
